package com.manage.project.biz.controller;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.manage.project.biz.domain.*;
import com.manage.project.biz.service.IBizGongluService;
import com.manage.project.biz.service.IBizSuidaoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.manage.framework.aspectj.lang.annotation.Log;
import com.manage.framework.web.controller.BaseController;
import com.manage.framework.aspectj.lang.enums.BusinessType;
import com.manage.framework.web.domain.AjaxResult;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.framework.web.page.TableDataInfo;

//import com.ruoyi.common.annotation.Log;
//import com.ruoyi.common.core.controller.BaseController;
//import com.ruoyi.common.core.domain.AjaxResult;
//import com.ruoyi.common.enums.BusinessType;
import com.manage.project.biz.service.ICivilEnginneeringTreatmentService;
//import com.ruoyi.common.utils.poi.ExcelUtil;
//import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 病害处治Controller
 *
 * @author ycd
 * @date 2022-05-30
 */
@RestController
@RequestMapping("/biz/treatment")
public class CivilEnginneeringTreatmentController extends BaseController
{
    @Autowired
    private ICivilEnginneeringTreatmentService civilEnginneeringTreatmentService;
    @Autowired
    private IBizGongluService roadInfoService;
    @Autowired
    private IBizSuidaoService iBizSuidaoService;

    /**
     * 查询病害处治列表
     */
    @PreAuthorize("@ss.hasPermi('biz:treatment:list')")
    @GetMapping("/list")
    public TableDataInfo list(CivilEnginneeringTreatment civilEnginneeringTreatment)
    {
        startPage();
        List<CivilEnginneeringTreatment> list = civilEnginneeringTreatmentService.selectCivilEnginneeringTreatmentList(civilEnginneeringTreatment);
        return getDataTable(list);
    }

    /**
     * 导出病害处治列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:treatment:export')")
//    @Log(title = "病害处治", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, CivilEnginneeringTreatment civilEnginneeringTreatment) throws IOException {
//        List<CivilEnginneeringTreatment> list = civilEnginneeringTreatmentService.selectCivilEnginneeringTreatmentList(civilEnginneeringTreatment);
//        ExcelUtil<CivilEnginneeringTreatment> util = new ExcelUtil<CivilEnginneeringTreatment>(CivilEnginneeringTreatment.class);
//        util.exportExcel(response, list, "病害处治数据");
//    }
    @Log(title = "病害处治", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CivilEnginneeringTreatment civilEnginneeringTreatment)
    {
        List<CivilEnginneeringTreatment> list = civilEnginneeringTreatmentService.selectCivilEnginneeringTreatmentList(civilEnginneeringTreatment);
        ExcelUtil<CivilEnginneeringTreatment> util = new ExcelUtil<CivilEnginneeringTreatment>(CivilEnginneeringTreatment.class);
        return util.exportExcel(list, "病害处治数据");
    }

    /**
     * 获取病害处治详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:treatment:query')")
    @GetMapping(value = "/{tTreatmentId}")
    public AjaxResult getInfo(@PathVariable("tTreatmentId") Long tTreatmentId)
    {
        return AjaxResult.success(civilEnginneeringTreatmentService.selectCivilEnginneeringTreatmentByTTreatmentId(tTreatmentId));
    }

    /**
     * 新增病害处治
     */
    @PreAuthorize("@ss.hasPermi('biz:treatment:add')")
    @Log(title = "病害处治", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CivilEnginneeringTreatment civilEnginneeringTreatment)
    {

        String roadName=civilEnginneeringTreatment.getRoadName();
        String tunnelName=civilEnginneeringTreatment.getTunnelName();
        String tunnelId=civilEnginneeringTreatment.getTunnelId();
        BizSuidao bizSuidao= iBizSuidaoService.getByTunnelNameIdAndRoadName(roadName,tunnelName,tunnelId);
        if(bizSuidao==null){
            return new AjaxResult().error("当前公路名称、隧道名称和隧道编码不对应，请核对后重新输入");
        }
        BizGonglu roadInfo=roadInfoService.checkByRoadName(roadName);
        if(roadInfo==null) {
            return new AjaxResult().error("当前道路不存在，请输入正确的道路名称");
        }else {
            return toAjax(civilEnginneeringTreatmentService.insertCivilEnginneeringTreatment(civilEnginneeringTreatment));

        }
    }

    /**
     * 修改病害处治
     */
    @PreAuthorize("@ss.hasPermi('biz:treatment:edit')")
    @Log(title = "病害处治", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CivilEnginneeringTreatment civilEnginneeringTreatment)
    {
        String roadName=civilEnginneeringTreatment.getRoadName();
        String tunnelName=civilEnginneeringTreatment.getTunnelName();
        String tunnelId=civilEnginneeringTreatment.getTunnelId();
        BizSuidao bizSuidao= iBizSuidaoService.getByTunnelNameIdAndRoadName(roadName,tunnelName,tunnelId);
        if(bizSuidao==null){
            return new AjaxResult().error("当前公路名称、隧道名称和隧道编码不对应，请核对后重新输入");
        }
        BizGonglu roadInfo=roadInfoService.checkByRoadName(roadName);
        if(roadInfo==null) {
            return new AjaxResult().error("当前道路不存在，请输入正确的道路名称");
        }else {
            return toAjax(civilEnginneeringTreatmentService.updateCivilEnginneeringTreatment(civilEnginneeringTreatment));
        }
    }

    /**
     * 删除病害处治
     */
    @PreAuthorize("@ss.hasPermi('biz:treatment:remove')")
    @Log(title = "病害处治", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tTreatmentIds}")
    public AjaxResult remove(@PathVariable Long[] tTreatmentIds)
    {
        return toAjax(civilEnginneeringTreatmentService.deleteCivilEnginneeringTreatmentByTTreatmentIds(tTreatmentIds));
    }
}
